package com.songlanyun.modules.rabbitmq.mq.consumer;

import com.fasterxml.jackson.core.type.TypeReference;
import com.rabbitmq.client.Channel;
import com.songlanyun.common.utils.custom.ClassConvertUtils;
import com.songlanyun.modules.publicbenefitmsg.model.to.PublicBenefitMsgTO;
import com.songlanyun.modules.rabbitmq.MqConstant;
import com.songlanyun.modules.rabbitmq.publicbenefitmsg.IPublicBenefitMsgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * 发送站内消息
 */
@Component
@Slf4j
public class PublicBenefitMsgConsumer extends BaseConsumer {

    @Resource
    private IPublicBenefitMsgService iPublicBenefitMsgService;

    @Override
    protected void process(Message message) throws IOException {
        String msgBody = new String(message.getBody());
        PublicBenefitMsgTO to = ClassConvertUtils.stringToClassSnake(msgBody, new TypeReference<PublicBenefitMsgTO>() {
        });

        iPublicBenefitMsgService.saveMsg(to);

    }

    @RabbitListener(queues = MqConstant.PublicBenefitMsgConstant.PUBLIC_BENEFIT_MSG_QUEUE)
    public void consume(Message message, Channel channel) throws IOException {
        super.handle(message, channel);
    }
}
